package com.taptech.doufu.db.userlog;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class UserLogDBHelper extends SQLiteOpenHelper {

    private static final String DB_NAME = "user_log.db";
    public static final String TABLE_NAME = "user_log_table";
    private static final int version = 1;


    public UserLogDBHelper(Context context){
        super(context,DB_NAME,null,version);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        try {
            Cursor cursor = db.rawQuery("SELECT * FROM sqlite_master WHERE type = ? AND name = ?",
                    new String[] { "table", TABLE_NAME });
            if (cursor.moveToNext()) {

            }else{
                db.execSQL("CREATE TABLE " + TABLE_NAME + " ("+
                        "_ID INTEGER PRIMARY KEY autoincrement, "
                        + "novel_id VARCHAR(1024), "    //小说ID
                        + "click_place VARCHAR(1024), "  //点击的地方
                        + "event_name VARCHAR(1024), "  //事件名称
                        + "pre_page VARCHAR(1024), "  //上一个页面
                        + "cur_page VARCHAR(1024), "  //当前页面
                        + "created_time DATETIME, "    //创建时间
                        + "read_time DATETIME, "    //阅读时长
                        + "uid VARCHAR(1024), "    //用户ID
                        + "keyword VARCHAR(1024)"  //关键词
                        + ");");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
